<?php
/*
 * @Author: lokei
 * @Date: 2022-11-05 22:11:15
 * @LastEditors: lokei
 * @LastEditTime: 2022-11-05 22:29:32
 * @Description: 
 */
namespace App\Http\Controllers\Master;

use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use App\Models\Master\ServiceModel;
use App\Models\Things\ServiceModel as ThingsServiceModel;
use Illuminate\Http\Request;

class ServiceController extends Controller {
    public function ofMaster(Request $request) {
        $items = ServiceModel::where('master_id', '=', $request->input('master_id'))->get();
        $res = ResultTool::success();
        $res['data']['items'] = $items;
        $res['data']['total'] = count($items);
        return $res;
    }

    public function create(Request $request) {
        $master_service = new ServiceModel();
        $master_service->master_id = $request->input('master_id');
        $master_service->service_id = $request->input('service_id');
        $service = ThingsServiceModel::where('id', '=', $request->input('service_id'))->first();
        $master_service->service_name = $service->name;
        $master_service->price = $request->input('price');
        $master_service->save();
        return ResultTool::success();
    }

    public function update(Request $request) {
        $master_service = ServiceModel::where('id', '=', $request->input('id'))->first();
        $master_service->price = $request->input('price');
        $master_service->save();
        return ResultTool::success();
    }

    public function delete(Request $request) {
        ServiceModel::where('id', '=', $request->input('id'))->delete();
        return ResultTool::success();
    }
}